package com.example.mapp;

import org.apache.ibatis.annotations.*;

import com.example.entity.Advertisement;

import java.util.List;
import java.util.Map;

/**
 * Created by douyx on 2018/03/26.
 */
@Mapper
public interface AdvertisementMapp {

	@Select(" select * from advertisement where discription = #{discription} order by id desc")
	List<Advertisement> query(Map map) throws Exception;

	@Select(" select A.*,B.title as infoTitle,B.file_urls as fileUrls from advertisement A left join information B on A.info_id =B.id order by A.id desc")
	List<Advertisement> queryAll() throws Exception;

	@Delete("delete from advertisement where id=#{id}")
	int delete(String id) throws Exception;

	@Insert(" insert into advertisement (url,discription,info_id,link_url,operate_type) value (#{url},#{discription},#{infoId},#{linkUrl},#{operateType})")
	@SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = Long.class)
	public int add(Advertisement advertisement) throws Exception;

	@Update("update advertisement set discription=#{discription},url=#{url},info_id=#{infoId},link_url=#{linkUrl},operate_type=#{operateType} where id=#{id}" )
	public int upDate (Advertisement advertisement) throws Exception;

	@Select("select * from advertisement where id=#{id}")
	public Advertisement queryById(Advertisement advertisement) throws  Exception;
}
